<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>局部变量和全局变量</title>
</head>
<body>
<script type="text/javascript">
    window.onload=function(){
        /*---------------------第一种情况------------*/
        //变量声明提前
       /* console.log(a);
        function a() //函数声明
        {
            this.user="追梦子";
        }*/
        /*---------------------第二种情况------------*/

        //函数表达式
       /* b();//Uncaught TypeError:a is not a function
        var b=function (){
            console.log(34);
        }*/


        /*---------------------第三种情况------------*/
      /*  var a=1;
        function c(){
            console.log(a);
            var a=5;
        }
        c();*/
        /*---------------------第四种情况------------*/
      /*  var a=1;
        function d(){
            a=120;
            return;
            function a(){}
        }
        d();
        alert(a);*/
      /*  var sayName = function(){
            var name = 'jozo';
            return function(){
                alert(name);
            }
        };
        var say = sayName();
        say();*/
    }
    /*---------------------第一种情况------------*/
   /* var param=1;
    function main (){
        var param;
        console.log(param);
        param=2;
        console.log(this.param);
        this.param=3;
    }
 main();
var m=main();*/
    /*---------------------第一种情况------------*/
/*    window.param=1;
    window.main=function(){
        console.log(param);
        var param=2;
        console.log(this.param);
        this.param=3;
    }
    main();
    window.main();
    var m=new main();*/
 let x=1, y=2;
 function foo(x) {
     let y=x;
     let obj={
         x:x++,
         y:--y,//
         setXY:function (a,y) {//1 2
             y=x+a;//x=4 y=5
             console.log('setXY:',x,this.x,y,this.y)//4 3 5 2
         },
         getXY:function () {
             console.log('getXY:',x,this.x,y,this.y)
             return x;
         },

     }
     return obj
 }

 let f=foo(3);//{x:3 y:2 setXY:getXY:}
 f.setXY(x,y);//4 3 5 2
 f.getXY();//4 3 2 2
 console.log('ouer:'+x,f.x,y,f.y)//1 3 2 2



</script>
</body>
</html>